#include "stdio.h"

struct worker{
    int number;
    int date[3];
    int start_time[3];
    int end_time[3];
};

struct worker information[3];

void input(struct worker *x);
void output(struct worker *a);
void sort_by_number(struct worker *y);
void sort_by_start(struct worker *z);
void sort_by_end(struct worker *q);
void best(struct worker *w);
void save(struct worker *p);
void reads(struct worker *e);

int main()
{
    int a;
    printf("1.输入员工考勤信息。\n2.按照员工号有序输出考勤信息。\n3.按照进公司时间有序输出考勤信息。\n4.按照离开公司时间有序输出考勤信息。\n5.输出优秀员工考勤信息，即当天工作时间最长的员工。\n6.员工考勤信息存入文件，文件名以日期命名。\n7.读取输入的日期，显示那天员工的考勤信息。\n");
    while (scanf("%d",&a)!=EOF) {
        switch (a) {
            case 1:input(information);break;
            case 2:sort_by_number(information);break;
            case 3:sort_by_start(information);break;
            case 4:sort_by_end(information);break;
            case 5:best(information);break;
            case 6:save(information);break;
            case 7:reads(information);break;
            default:printf("no such operation\n");break;
        }
    }
    return 0;
}

void input(struct worker *x){
    for (int i=0; i<3;i++) {
        scanf("%d %d %d %d %d %d %d %d %d %d\n",&((x+i)->number),&((x+i)->date[0]),&((x+i)->date[1]),&((x+i)->date[2]),&((x+i)->start_time[0]),&((x+i)->start_time[1]),&((x+i)->start_time[2]),&((x+i)->end_time[0]),&((x+i)->end_time[1]),&((x+i)->end_time[2]));
    }
}

void output(struct worker *a){
    for (int t=0; t<3; t++) {
        printf("%d %d-%d-%d %d:%d:%d %d:%d:%d\n",(a+t)->number,(a+t)->date[0],(a+t)->date[1],(a+t)->date[2],(a+t)->start_time[0],(a+t)->start_time[1],(a+t)->start_time[2],(a+t)->end_time[0],(a+t)->end_time[1],(a+t)->end_time[2]);
    }
}

void sort_by_number(struct worker *y){
    for (int i=0; i<2; i++) {
        for (int j=0; j<2-i; j++) {
            if ((y+j)->number>(y+j+1)->number) {
                struct worker temp;
                temp=*(y+j);
                *(y+j)=*(y+j+1);
                *(y+j+1)=temp;
            }
        }
    }
    output(y);
}

void sort_by_start(struct worker *z){
    double min[3];
    for (int i=0; i<3; i++) {
        min[i]=((z+i)->start_time[0])*60+(z+i)->start_time[1]+((z+i)->start_time[2])/60;
    }
    for (int i=0; i<2; i++) {
        for (int j=0; j<2-i; j++) {m
            if (min[j]>min[j+1]) {
                double t;
                t=min[j];
                min[j]=min[j+1];
                min[j+1]=t;
                struct worker temp;
                temp=*(z+j);
                *(z+j)=*(z+j+1);
                *(z+j+1)=temp;
            }
        }
    }
    output(z);
}

void sort_by_end(struct worker *q){
    double min[3];
    for (int i=0; i<3; i++) {
        min[i]=((q+i)->end_time[0])*60+(q+i)->end_time[1]+((q+i)->end_time[2]);
    }
    for (int i=0; i<2; i++) {
        for (int j=0; j<2-i; j++) {
            if (min[j]>min[j+1]) {
                double t;
                t=min[j];
                min[j]=min[j+1];
                min[j+1]=t;
                struct worker temp;
                temp=*(q+j);
                *(q+j)=*(q+j+1);
                *(q+j+1)=temp;
            }
        }
    }
    output(q);
}

void best(struct worker *w){
    double startmin[3];
    double endmin[3];
    double total[3];
    for (int i=0; i<3; i++) {
        startmin[i]=((w+i)->start_time[0])*60+(w+i)->start_time[1]+((w+i)->start_time[2])/60;
    }
    for (int i=0; i<3; i++) {
        endmin[i]=((w+i)->end_time[0])*60+(w+i)->end_time[1]+((w+i)->end_time[2]);
    }
    for (int i=0; i<3; i++) {
        total[i]=endmin[i]-startmin[i];
    }
    for (int i=0; i<2; i++) {
        for (int j=0; j<2-i; j++) {
            if (total[j]>total[j+1]) {
                double t;
                t=total[j];
                total[j]=total[j+1];
                total[j+1]=t;
                struct worker temp;
                temp=*(w+j);
                *(w+j)=*(w+j+1);
                *(w+j+1)=temp;
            }
        }
    }
    printf("%d",(w+2)->number);
}

void save(struct worker *p){
    FILE *fp1;
    char s[10];
    sprintf(s, "%d",information->date[0],information->date[1],information[2]);
    strcat(s,".txt");
    if ((fp1=fopen(s, "w"))!=0) {
        fwrite(p, sizeof(struct worker), 3, fp1);
    }
    fclose(fp1);
}

void reads(struct worker *e){
    FILE *fp2;
    char s[10];
    sprintf(s, "%d",sinformation->date[0],information->date[1],information[2]);
    strcat(s,".txt");
    fp2=fopen(s, "r");
    fread(e, sizeof(struct worker), 3, fp2);
    fclose(fp2);
}